package cn.klaw.database.plugins;

import cn.dev33.satoken.context.SaHolder;
import cn.klaw.util.StringUtil;
import cn.klaw.util.UserProvider;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.function.Consumer;

public interface ITenantPlugin {

    default void printNoTenant(Consumer<NoTenantInfoModel> logConsumer){
        String token = null;
        String url = null;
        String stack = null;
        String userId = UserProvider.getUser().getTenantId();
        try{
            token = UserProvider.getToken();
            url = SaHolder.getRequest().getRequestPath();
        }catch (Exception e){}
        if(url == null){
            try{
                stack = StringUtil.join(Thread.currentThread().getStackTrace(), "\n");
            }catch (Exception e){}
        }
        logConsumer.accept(new NoTenantInfoModel(token, url, stack, userId));
    }

}

@Data
@AllArgsConstructor
class NoTenantInfoModel{
    private String token;
    private String url;
    private String stack;
    private String userId;
}
